home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 026-050 / scopedisk32 / bb1 / blockbuster.doc < prev    next >
Text File  |  1995-03-18  |  17KB  |  360 lines

  1. Blockbuster Disk Editor
  2. by Ken Turcotte
  3.  
  4.  
  5. If you've ever wondered how information is stored on floppy disks
  6. then Blockbuster -- my utility program that lets you examine and
  7. modify 3.5 inch floppy disks at the sector level -- is for you.
  8.   Blockbuster is useful for performing operations that the
  9. Amiga's Disk Operating System (DOS) does not support, and for
  10. modifying programs that you otherwise could not change.  If you're
  11. familiar with the CLI you'll be right at home with it.  Unlike
  12. traditional sector editors, Blockbuster automatically follows
  13. directory paths and moves through files.  With its FIND feature you
  14. can search an entire disk for a key word.  For example, say you want
  15. to install a program that always looks for a data file on dh0:, your
  16. hard drive.  Simply search for df0: on the disk that program is stored
  17. on by clicking on the FIND gadget, and entering df0:.  When the proper
  18. occurrence has been found, change the f to h (changing f for Floppy to
  19. h for Hard) and write the modified sector to the disk.  That will
  20. provide you with a modified version of the program on floppy; copy it
  21. onto your hard drive and you're off.
  22.  
  23. Before we go into using Blockbuster however let's start with some
  24. information about the AmigaDOS 1.2 filing system, the vast majority of
  25. which will still be pertinent under the new Workbench 1.3 version that
  26. Commodore, in its inimitable style, has been threatening to ship for
  27. months.
  28.  
  29. Tracks, Sectors, Cylinders and Blocks
  30.  
  31. Although this lingo seems more appropriate to racing cars than
  32. computers, the Amiga uses 3.5 inch double- sided floppy disks that are
  33. addressed in this manner.  Information is recorded on disks in
  34. concentric circles called tracks. 
  35.  
  36. There are tracks on both the bottom and top surfaces of a disk. 
  37. There are also two heads in a disk drive, one for each side of the
  38. disk.  These two heads are positioned by a single stepper motor which
  39. means that the heads are always opposite of each other, and the two
  40. opposing tracks make up another unit called a cylinder. Anyone who has
  41. formatted or duplicated a disk has seen the term cylinder before. 
  42. Notice that you will hear the heads move each time the cylinder number
  43. changes.
  44.  
  45. Each track can be broken down further into a unit called a
  46. sector.  A sector holds 512 bytes of data.  This smaller unit is used
  47. to make the disk more manageable.  This 512 byte unit is also known as
  48. a block.  There are 11 sectors or blocks on each track;  double this
  49. because the disk is double-sided and we have 22 sectors per cylinder.
  50.  
  51. There is enough room on a disk to hold 80 cylinders.  This means
  52. that a disk can hold 1760 sectors.  Each sector holds .5 K of data,
  53. for a total storage capacity of 880K.  Normally the cylinders are
  54. numbered from 0 to 79 and the sectors on each track are numbered from
  55. 0 to 11.  Each surface also has it's own number, either 0 or 1.  The
  56. upshot of all these numbers is that in order to access any sector on
  57. the disk we must know the cylinder, sector and head number.
  58.  
  59. To simplify locating data, DOS numbers all of the blocks on disk
  60. from 0 to 1759.  This is known as an offset and is passed from DOS to
  61. the trackdisk.device.  The trackdisk.device then converts the offset
  62. into a cylinder, sector and head number.  This means that DOS does not
  63. have to know any details about the physical layout of the device and
  64. makes it possible for DOS to use the same filing system on another
  65. device such as a hard drive.  All that is required is a new device
  66. driver.
  67.  
  68. But what does DOS DO?
  69.  
  70. It is the job of the DOS -- remember, that's short for Disk
  71. Operating System --  to organize the blocks on a disk.  This means
  72. keeping track of which blocks contain files, and which locks are free
  73. to be used.  Commodore has documented five different block types in
  74. the AmigaDOS manual:
  75.  
  76. 1.  Root block
  77. 2.  User directory block
  78. 3.  File header block
  79. 4.  Data block
  80. 5.  File list block.
  81.  
  82. Each block is broken up into long word fields (4 bytes).  The
  83. AmigaDOS manual states that these fields are of the word size.  This
  84. is incorrect.  Blockbuster can be used to identify these fields by
  85. positioning the cursor on them.  A short description of the field will
  86. appear on the lower right side of the screen.
  87.  
  88. You can identify each block by checking the first and last field
  89. of the block.  The first field is called the type, and the last field
  90. is called the secondary type.  Data blocks do not have a secondary
  91. type field.  The table below shows you how to determine the block
  92. type.  Blockbuster will always calculate the block type and display it
  93. on the bottom of the screen below the hex display.  Any non-documented
  94. blocks will appear as block type unknown.
  95.  
  96. Block          Type           Secondary
  97.  
  98. File list       1               -3
  99. Root Block      2                1
  100. User Dir        2                2
  101. File Header     2               -3
  102. Data Block      8               none
  103.  
  104. There are many common long word information fields among the five
  105. documented block types.  These fields include the header key, highest
  106. seq, Size, checksum, parent, and creation date.  They are located at
  107. the beginning and near the ends of the blocks.  It is generally the
  108. center area of the blocks that differ.  Blockbuster automatically
  109. identifies which field the cursor is on, all you have to do is move
  110. the cursor keys around.  Fields are described in the following
  111. sections.
  112.  
  113. The Root Block
  114.  
  115. The root block is the most important block on the disk.  There is
  116. only one root block on each disk and it appears on Block $370
  117. (cylinder 40, sector 0 head 0).  This positions it in the middle of
  118. disk. It contains the name of the disk, the time and date the disk was
  119. created, the time and date the disk was last written to, a hash table,
  120. and bitmap information.
  121.  
  122. The disk name is stored as a BCPL string.  This means the first
  123. byte of the disk name field contains the length of the name and the
  124. following bytes contain the name itself.
  125.  
  126. EAlthough two disks may have the same name they will never have
  127. the same creation date and time.  It is this fact that is used by
  128. AmigaDOS to distinguish two disks with the same name.  If you wish
  129. AmigaDOS to think that two disk are the same, change this time and
  130. date.
  131.  
  132. The hash table is a list of the entries in the root directory. 
  133. It consists of 72 long words.  Each long word can be either 0 or the
  134. block number containing an entry.  Each entry will be a file header or
  135. a user directory block.  Double click on any hash table entry and this
  136. block will be displayed on the screen.  Clicking the INTO gadget with
  137. the root block displayed on the screen will display the first entry in
  138. the hash table.  Continue by clicking NEXT to move through the entries
  139. of the hash table.  This is similar to listing a directory from CLI. 
  140. Clicking the DIR B gadget will always return the display to the root
  141. block.
  142.  
  143. The bitmap information consists of a bitmap flag and 26 entries
  144. for bitmap pages.  This is a map of all the blocks on the disk and an
  145. Amiga 3.5 inch floppy will never need more that one bitmap page.  It
  146. is used to determine which blocks are free and which are used.  The
  147. bitmap flag indicates if the bitmap is currently valid.  If this long
  148. word is 0 then the bitmap is not valid.  Whenever you insert a disk
  149. with this flag set to zero into a drive, the disk-validator program
  150. from the l directory of the Workbench disk is executed. 
  151. Disk-validator tracks down which blocks are used.  A new bitmap is
  152. then Cached in computer memory.  The next time a file is written to
  153. this disk the bitmap is corrected and the flag is set to a non-zero
  154. value.
  155.  
  156. Blockbuster displays the bitmap page of a disk when you click the
  157. MAP gadget.  It draws a grid to indicate which blocks are free and
  158. which are in use.  Free blocks will be white if you have not changed
  159. the system colors in Preferences.  To return to where you left, click
  160. on the CLOSE gadget. Optionally you may click on any block on the map
  161. grid and this block will be displayed.
  162.  
  163. Common Root Block Fields
  164.  
  165. All times and dates are stored using the standard Amiga date
  166. format.  This is three long words indicating the amount of time
  167. elapsed in days, minutes, and tics since January 1, 1978.  The
  168. creation time is also included in the user dir block and file header
  169. block.  It is located in the same place in all three block types which
  170. makes it easy to locate.  The last altered time and date is unique to
  171. the root block.
  172.  
  173. The header key is a long word field pointing to the block's
  174. header block.  The root block has no header, therefore this field will
  175. always be zero.  All block types contain a header key field but only
  176. the data block and file list block make use of it.
  177.  
  178. The highest seq is only used in the data block and file list
  179. block.  For all other block types, including the root block, it will
  180. be zero.
  181.  
  182. The size field of the root block contains the size of the hash
  183. table.  This is always 72 long words long.  The size field is included
  184. in all five block types but is used for a different purpose in all
  185. cases.
  186.  
  187. The first data field is used only in the file header and data
  188. blocks.  In the root block this will always contain a zero.
  189.  
  190. The checksum is used to indicate if a block is valid.  All five
  191. of the documented block types contain a checksum which is calculated
  192. so that the sum of all of the long words in a block ignoring overflow
  193. equals zero.  To check to see if a block is valid, add together all
  194. the long words and the result should be zero.  Blockbuster will always
  195. calculate a correct checksum before it writes a sector to disk.
  196.  
  197. User Directory Block
  198.  
  199. The user directory block is similar to the root block.  There is
  200. one user directory block for each sub- directory on a disk.  More
  201. important information is the hash table, creation date, directory
  202. name, comment and parent.  The first three of these are identical to
  203. the root block.  The comment field is used to store a BCPL string
  204. attached with the CLI command filenote.  The parent field contains the
  205. block number of this directory's parent.  This may point to a root
  206. block, or another user directory block.
  207.  
  208. It is interesting to note that if you rename a file or directory
  209. the unused portion of the name field remains untouched.  This may be
  210. useful for detecting if a program is an original or a copy.
  211.  
  212. File Header Block
  213.  
  214. The file header block contains all the information about a file,
  215. but none of the file's contents.  This includes the file name,
  216. creation date and time, size in bytes, protection bits, and file
  217. comment.  It also contains a list of all the data blocks used for the
  218. file, the number of data blocks used, and a pointer to the file's
  219. parent directory.
  220.  
  221. The data block list contains the block numbers of all the data
  222. blocks used.  The list starts at the end of the block list field and
  223. works backwards.  By double clicking on any entry in the data block
  224. list you can move directly to that data block.  It is also possible to
  225. click on the INTO gadget to display the first data block of the file. 
  226. Repeatedly clicking on the NEXT gadget moves forward through the data
  227. block.  Clicking on the LAST gadget will take you back to the file
  228. header block.
  229.  
  230. The data block list is used by DOS to locate any position in the
  231. file without having to search through all the data blocks -- and this
  232. gives you random access.
  233.  
  234. File List Block
  235.  
  236. The file list block is an extension of the file header block.  If
  237. the file contains more blocks than can be listed in the file header
  238. block, then the extension field of the file header will point to a
  239. file list block.  The file list block is just a continuation of this
  240. list.  For most files there will be no file list block but larger
  241. files may have multiple file list blocks.
  242.  
  243. Data Block
  244.  
  245. The data block is used to store the contents of a file.  Each
  246. file may have one or multiple data blocks.  All data blocks have the
  247. six standard information fields at the beginning.
  248.  
  249. The header key of the data block contains the block number of the
  250. file header block.  Clicking the LAST gadget will display this block.
  251.  
  252. The sequence number contains the blocks position in the file.
  253.  
  254. Data size indicates how many data bytes are contained in this
  255. block.  Typically this will be 488 bytes.  The exception will be when
  256. this is the last data block of the file.
  257.  
  258. Next data will contain the block number of the next data block in
  259. this file.  If the file header block is damaged then this field can be
  260. used to paste the file back together.  If this is the last data block
  261. this field will contain a zero.
  262.  
  263. The data field is 488 bytes long.  If the value in data size is
  264. less than 488, then part of the data field will contain garbage.  When
  265. file copy is used to duplicate a file the unused portion of the last
  266. data block is not duplicated.
  267.  
  268. Undocumented blocks
  269.  
  270. The Amiga filing system has two block types not documented in the
  271. AmigaDOS manual.  These are the boot block and the bitmap block.
  272.  
  273. The boot block is actually two reserved blocks.  Blocks 0 and 1
  274. have been set aside for this purpose.  The first four bytes of block
  275. zero are used to indicate if the disk is a DOS disk.  They will
  276. normally contain the letters 'DOS' followed by a zero.
  277.  
  278. Normally when you use the CLI command INSTALL a small program
  279. called a bootstrap is written to these two sectors.  When the Amiga is
  280. powering up, block zero is checked to see if it contains this
  281. bootstrap.  If the bootstrap exists it is loaded into memory and
  282. executed.  This program will usually carry out the normal startup-
  283. sequence found in the s directory on Workbench disks.  Some commercial
  284. programs contain a custom bootstrap program.  These programs usually
  285. take over complete control of the Amiga hardware.
  286.  
  287. Recently, a third type of boot block has emerged.  This is called
  288. a virus.   I've came across three different viruses, however have heard
  289. rumors of as many as five.  Blockbuster can be used to detect viruses by
  290. inserting a disk and clicking on the BOOT B gadget.  
  291. This will display the boot block on the screen.  A normal boot block will
  292. contain the word dos.library near the top of the block.  If it isn't there
  293. you know that this is not the standard boot block.  Examine the ASCII 
  294. display of the block or suspicious messages like "virus by byte bandit"
  295. or "something wonderful has happened to your Amiga."  Remember to check
  296. block 1 as well.  To move to block 1 click on the sector advance gadget.
  297. The SCA virus puts it's messages on block 1.
  298.  
  299. One way to remove some viruses is to use the INSTALL command from
  300. the CLI.  Buy remember that if you booted from that disk, the virus
  301. will be in memory and may reinstall itself as soon as it is removed.
  302.  
  303. The other undocumented block is the bitmap page.  A pointer to
  304. the bitmap page can be found in the root block.  Double click on the
  305. bitmap page entry and it will be displayed.  Unlike the other
  306. documented block types which have the checksum as the 6th long word of
  307. the block, the bitmap block has the checksum as the first long word. 
  308. This means that if you want to modify the bitmap page using
  309. -Blockbuster you must manually calculate a checksum.
  310.  
  311. Each block on the disk has one bit in the bitmap.  When a disk is
  312. formatted most of the bits will be set to 1 indicating that the block
  313. is free.  The blocks that will be allocated are the bitmap, root block
  314. and two boot blocks.  There may also be blocks allocated for
  315. Workbench-related files depending on how you formatted the disk.  The
  316. easiest way to make any sense of the bitmap is to click on the MAP
  317. gadget.
  318.  
  319. Tricks with the Filing System
  320.  
  321. It is possible to do many things with the filing system.  One
  322. example of this is recovering accidentally deleted files.  The easiest
  323. way is to use the DOSKDOCTOR program provided on Workbench which
  324. locates all the file headers and builds new directories.
  325.  
  326. The primary problem with this method is keeping other programs
  327. from making changes on the disk before the file is recovered.  DOS
  328. will occasionally move the bitmap page onto a deleted file, or
  329. Workbench will rewrite its .info files.  Trying to recover files when
  330. more than one file has been deleted is easier.  Usually you can
  331. recover all of the files but one. 
  332.  
  333.  
  334. BLOCKBUSTER Command Summary
  335.  
  336. Gadgets
  337.  
  338. FIND  - Searches for a string from current block.
  339. NEXT  - Moves to next file in hash table, or data block 
  340. LAST  - Moves to file header or parent directory.
  341. INTO  - Moves into directory or file.
  342. BOOTB - Moves to the boot block.
  343. DIR B - Moves to the root block.
  344. END B - moves to the last cylinder of the disk.
  345. SECT  - Change sector.
  346. CLY   - Change cylinder.
  347. H     - Toggle drive head. (0 / 1)
  348. D     - Toggle drive number. (df0: / df1:)
  349.  
  350. Keyboard
  351.  
  352. X      - Exits program
  353. HEX    - 0-F on main keyboard used to edit block
  354. CURSOR - Moves both hex and ascii cursors.
  355.  
  356. Menu
  357.  
  358. WRITE/SECTOR  - Writes current block to disk.
  359.  
  360.